package com.example.lx5_27.visit

import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.example.base.entity.Res
import com.example.base.entity.VisitEntity
import com.example.base.entity.VisitEntityItem
import com.example.base.net.ApiService

class VisitDataSource(val apiService: ApiService,val s:String,val s1:String) : PagingSource<Int,VisitEntityItem>() {
    override fun getRefreshKey(state: PagingState<Int, VisitEntityItem>): Int? {
        return null
    }

    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, VisitEntityItem> {
        try {
            var visit : Res<VisitEntity> ?= null
            if(s1 == "状态"){
                visit = apiService.getType(s)
            }else{
                visit = apiService.getVisit()
            }
            return LoadResult.Page(visit.data,null,null)
        }catch (e:Exception){
            return LoadResult.Error(e)
        }
    }
}